package br.edu.unilasalle.simon_api.rs;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;

import br.edu.unilasalle.simon_api.domain.CondicaoPagamento;
import br.edu.unilasalle.simon_api.service.ICondPagtoService;

@Path("/condPagto")
public class CondPagtoRS {
	
	@Autowired
	private ICondPagtoService service;
	
	@GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<CondicaoPagamento> findAllCondPagto() {
		return service.findAllCondPagto();
    }

    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public CondicaoPagamento findById(@PathParam("id") long id) {
        return service.findById(id);
    }
    
    @GET
    @Path("/valor")
    @Produces(MediaType.TEXT_PLAIN)
    public Boolean findById(@QueryParam("valor") double valor, @QueryParam("idFormPagto") long idFormPagto, @QueryParam("parcelas") int parcelas) {
        return service.findByValor(valor, idFormPagto, parcelas);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public CondicaoPagamento create(CondicaoPagamento obj) {
        return service.save(obj);
    }

    @PUT
    @Path("{id}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public CondicaoPagamento update(CondicaoPagamento obj) {
    	service.save(obj);
    	return obj;
    }

    @DELETE
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public void delete(@PathParam("id") long id) {
    	service.deleteById(id);
    }

}
